package com.xiaoluo.service;

import com.xiaoluo.cd.dao.ServersMapper;
import com.xiaoluo.cd.entity.base.Servers;
import com.xiaoluo.cd.entity.base.ServersExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Project : XL-CD
 * Package : com.xiaoluo.service
 * Created by Willian.
 * Date  : 2015/12/28 14:55.
 */
@Service
@Transactional
public class ServerService {
    private final static Logger logger = LoggerFactory.getLogger(ServerService.class);

    @Autowired
    ServersMapper serversMapper;

    /**
     *
     * @return
     */
    public List<Servers> list(){
        return serversMapper.selectByExample(null);
    }

    /**
     *
     * @param id
     * @return
     */
    public Servers get(Long id){
        return serversMapper.selectByPrimaryKey(id);
    }

    public void del(Long id){
        serversMapper.deleteByPrimaryKey(id);
    }

    /**
     * 保存
      * @param servers
     */
    public void save(Servers servers){
        if(servers.getId() != null){
            serversMapper.updateByPrimaryKey(servers);
        }else {
            serversMapper.insert(servers);
        }
    }
    /**
     *
     * @param type
     * @return
     */
    public List<Servers> queryByType(Integer type){
        ServersExample example = new ServersExample();
        example.createCriteria().andTypeEqualTo(type.byteValue());
        return serversMapper.selectByExample(example);
    }
}
